//
//  BargainTableViewCell.m
//  quxiangtao
//
//  Created by E人一铺 on 2019/2/27.
//  Copyright © 2019年 shanhaijin. All rights reserved.
//

#import "BargainTableViewCell.h"
#import "BargainTableViewModel.h"

@interface BargainTableViewCell ()
@property (weak, nonatomic) IBOutlet UIImageView *goodsImage;
@property (weak, nonatomic) IBOutlet UILabel *goodsTitle;
@property (weak, nonatomic) IBOutlet UILabel *goodsCount;
@property (weak, nonatomic) IBOutlet UILabel *goodsPrice;
@property (weak, nonatomic) IBOutlet UILabel *status;




@end


@implementation BargainTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}
- (void)setModel:(BargainTableViewModel *)model {
    
    _model = model;
    
    
    NSString *picStr = @"";
    if ([model.goods_logo hasPrefix:@"http://"] || [model.goods_logo hasPrefix:@"https://"]) {
        picStr = model.goods_logo;
    }else {
        picStr = [NSString stringWithFormat:@"http://%@", model.goods_logo];
    }
    [self.goodsImage sd_setImageWithURL:[NSURL URLWithString:picStr]];
    self.goodsTitle.text = [NSString stringWithFormat:@"%@ %@", model.goods_name, model.goods_specification];
    
    self.goodsCount.text = [NSString stringWithFormat:@"已砍%@件", model.bargainCount];
    self.goodsPrice.text = model.goods_price;
    
    self.goodsPrice.attributedText = [self AttributedString: [NSString stringWithFormat:@"¥%@", model.goods_price]];
    
    if ([model.status intValue] == 0) {
        self.status.text = @"砍价中";
    }else if ([model.status intValue] == 1)
    {
        self.status.text = @"砍价成功";
    }
    else if ([model.status intValue] == 2)
    {
        self.status.text = @"砍价过期";
    }
    else if ([model.status intValue] == 3)
    {
        self.status.text = @"退款";
    }

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}
- (NSMutableAttributedString *)AttributedString:(NSString *)string
{
    NSArray *arr = [string componentsSeparatedByString:@"."];
    
    // 创建Attributed
    NSMutableAttributedString *noteStr = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@.%@",arr.firstObject,arr.lastObject]];
    
    //第一部分修改
    // 需要改变的第一个文字的位置
    NSUInteger firstLoc = 0;
    // 需要改变的最后一个文字的位置
    NSUInteger secondLoc = [[noteStr string] rangeOfString:@"."].location;
    // 需要改变的区间
    NSRange range = NSMakeRange(firstLoc, secondLoc - firstLoc);
    
    // 改变字体大小及类型
    [noteStr addAttribute:NSFontAttributeName value:Font(32) range:range];
    
    
    //第二部分修改
    // 需要改变的第一个文字的位置
    NSUInteger firstLoc1 = [[noteStr string] rangeOfString:@"."].location + 1;
    // 需要改变的最后一个文字的位置
    NSUInteger secondLoc1 = [noteStr string].length;
    // 需要改变的区间
    NSRange range1 = NSMakeRange(firstLoc1, secondLoc1 - firstLoc1);
    
    // 改变字体大小及类型
    [noteStr addAttribute:NSFontAttributeName value:Font(20) range:range1];
    
    return noteStr;
    
    
}


@end
